From c4db5246aa43757c0bdfd7d7e46f5e11e176dab6 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Wed, 15 Nov 2006 16:44:35 +0000 Subject: [PATCH] [XEN] Define remaining x86 public pointer fields as guest handles. Signed-off-by: Jan Beulich Signed-off-by: Keir Fraser --- xen/arch/x86/domain.c | 14 ++++++-------- xen/arch/x86/mm.c | 2 +- xen/arch/x86/physdev.c | 2 +- xen/arch/x86/traps.c | 18 +++++++++++++++--- xen/include/asm-x86/domain.h | 2 +- xen/include/public/physdev.h | 3 +-- xen/include/public/vcpu.h | 7 +++++-- xen/include/public/xen-compat.h | 9 ++++++++- xen/include/public/xen.h | 2 +- xen/include/xen/sched.h | 2 +- 10 files changed, 40 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index ce522cdcf5..80af1222fa 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -396,21 +396,20 @@ arch_do_vcpu_op( if ( copy_from_guest(&area, arg, 1) ) break; - if ( !access_ok(area.addr.v, sizeof(*area.addr.v)) ) + if ( !guest_handle_okay(area.addr.h, 1) ) break; rc = 0; - v->runstate_guest = area.addr.v; + v->runstate_guest = area.addr.h; if ( v == current ) { - __copy_to_user(v->runstate_guest, &v->runstate, - sizeof(v->runstate)); + __copy_to_guest(v->runstate_guest, &v->runstate, 1); } else { vcpu_runstate_get(v, &runstate); - __copy_to_user(v->runstate_guest, &runstate, sizeof(runstate)); + __copy_to_guest(v->runstate_guest, &runstate, 1); } break; @@ -767,9 +766,8 @@ void context_switch(struct vcpu *prev, struct vcpu *next) context_saved(prev); /* Update per-VCPU guest runstate shared memory area (if registered). */ - if ( next->runstate_guest != NULL ) - __copy_to_user(next->runstate_guest, &next->runstate, - sizeof(next->runstate)); + if ( !guest_handle_is_null(next->runstate_guest) ) + __copy_to_guest(next->runstate_guest, &next->runstate, 1); schedule_tail(next); BUG(); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 2ca0826d14..c7dc88d503 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -2067,7 +2067,7 @@ int do_mmuext_op( { unsigned long vmask; cpumask_t pmask; - if ( unlikely(get_user(vmask, (unsigned long *)op.arg2.vcpumask)) ) + if ( unlikely(copy_from_guest(&vmask, op.arg2.vcpumask, 1)) ) { okay = 0; break; diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index cde604bffc..d24aad62aa 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -125,7 +125,7 @@ long do_physdev_op(int cmd, XEN_GUEST_HANDLE(void) arg) if ( copy_from_guest(&set_iobitmap, arg, 1) != 0 ) break; ret = -EINVAL; - if ( !access_ok(set_iobitmap.bitmap, IOBMP_BYTES) || + if ( !guest_handle_okay(set_iobitmap.bitmap, IOBMP_BYTES) || (set_iobitmap.nr_ports > 65536) ) break; ret = 0; diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 2b5a97cce2..33194a22a5 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -952,7 +952,6 @@ static inline int guest_io_okay( unsigned int port, unsigned int bytes, struct vcpu *v, struct cpu_user_regs *regs) { - u16 x; #if defined(__x86_64__) /* If in user mode, switch to kernel mode just to read I/O bitmap. */ int user_mode = !(v->arch.flags & TF_kernel_mode); @@ -967,10 +966,23 @@ static inline int guest_io_okay( if ( v->arch.iobmp_limit > (port + bytes) ) { + union { uint8_t bytes[2]; uint16_t mask; } x; + + /* + * Grab permission bytes from guest space. Inaccessible bytes are + * read as 0xff (no access allowed). + */ TOGGLE_MODE(); - __get_user(x, (u16 *)(v->arch.iobmp+(port>>3))); + switch ( __copy_from_guest_offset(&x.bytes[0], v->arch.iobmp, + port>>3, 2) ) + { + default: x.bytes[0] = ~0; + case 1: x.bytes[1] = ~0; + case 0: break; + } TOGGLE_MODE(); - if ( (x & (((1<= 0x00030205 +#define XEN_GUEST_HANDLE_00030205(type) XEN_GUEST_HANDLE(type) +#else +#define XEN_GUEST_HANDLE_00030205(type) type * +#endif + #endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */ diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index f44d61fd10..1b810df364 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -246,7 +246,7 @@ struct mmuext_op { /* SET_LDT */ unsigned int nr_ents; /* TLB_FLUSH_MULTI, INVLPG_MULTI */ - void *vcpumask; + XEN_GUEST_HANDLE_00030205(void) vcpumask; } arg2; }; typedef struct mmuext_op mmuext_op_t; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index d08959cab1..bb9dcd741f 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -75,7 +75,7 @@ struct vcpu void *sched_priv; /* scheduler-specific data */ struct vcpu_runstate_info runstate; - struct vcpu_runstate_info *runstate_guest; /* guest address */ + XEN_GUEST_HANDLE(vcpu_runstate_info_t) runstate_guest; /* guest address */ unsigned long vcpu_flags; -- 2.30.2